/*
 * @Author: taoyuqing
 * @Date: 2022-12-23 01:05:58
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';
import 'package:spree/pages/loginPage/login_page.dart';
import 'package:spree/pages/profileMenu/profile_menu.dart';
import 'package:spree/utils/utils.dart';
import 'package:spree/widgets/common_container.dart';
import 'package:spree/widgets/vip_content_box.dart';
import 'package:spree/widgets/vip_rectangle_box.dart';

import '../provider/model/user_model.dart';
import '../widgets/progress_bar.dart';
import 'package:spree/consts/profile_skip_alias.dart';
import 'package:spree/consts/page_const.dart';

// import 'package:web_socket_channel/io.dart';
class ProfilePage extends StatefulWidget {
  ProfilePage({Key? key}) : super(key: key);
  @override
  State<ProfilePage> createState() => _ProfilePageState();
}

class _ProfilePageState extends State<ProfilePage> {
  List _wallet = [
    {
      'icon': Image.asset('images/deposit-icon.png'),
      'name': 'deposit',
      'alias': 'DepositPage'
    },
    {
      'icon': Image.asset('images/draw-detail-icon.png'),
      'name': 'detail',
      'alias': 'OrderHistoryPage'
    },
    {
      'icon': Image.asset('images/draw-icon.png'),
      'name': 'withdraw',
      'alias': 'WithdrawnPage'
    },
    {
      'icon': Image.asset('images/fait-icon.png'),
      'name': 'invitation',
      'alias': 'ReferalPage'
    },
  ];
  List _games = [
    {
      'icon': Image.asset('images/history-icon.png'),
      'name': 'History',
      'alias': 'HistoryPage'
    },
    {
      'icon': Image.asset('images/crash-icon.png'),
      'name': 'Crash',
      'alias': 'Crash'
    },
    {
      'icon': Image.asset('images/dice-icon.png'),
      'name': 'Dice',
      'alias': 'Dice'
    },
    {
      'icon': Image.asset('images/mines-icon.png'),
      'name': 'Mines',
      'alias': 'Mines'
    },
    {
      'icon': Image.asset('images/double-icon.png'),
      'name': 'Double',
      'alias': 'Double'
    },
    {
      'icon': SvgPicture.asset('images/all.svg'),
      'name': 'All games',
      'alias': 'GameSearchPage'
    },
  ];
  bool _hasLogin = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: Text(
            'Profile',
            style: TextStyle(color: Colors.white),
          ),
        ),
        body: Consumer<UserModel>(
          builder: (context, value, child) {
            return CommonContainer(
              child: ListView(
                padding: EdgeInsets.only(top: 30),
                children: [
                  Container(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        GestureDetector(
                          onTap: () {
                            if (value.userId == '') {
                              Navigator.pushNamed(context, 'LoginPage');
                              return;
                            }
                            Navigator.pushNamed(context, 'ChangeUserInfo');
                          },
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Container(
                                width: 50,
                                height: 50,
                                child: ClipOval(
                                    child: value.avatar == ''
                                        ? Image.asset(
                                            'images/avatar.jpg',
                                            fit: BoxFit.cover,
                                          )
                                        : Image.network(
                                            '${value.avatar}',
                                            fit: BoxFit.cover,
                                          )),
                              ),
                              Container(
                                margin: EdgeInsets.only(left: 10),
                                child: Text(
                                  '${value.nickname != '' ? value.nickname : 'click to login in'}',
                                  style: TextStyle(
                                      color: Colors.white,
                                      fontWeight: FontWeight.w600),
                                ),
                              ),
                            ],
                          ),
                        ),
                        Container(
                            margin: EdgeInsets.only(top: 10),
                            child: Row(
                              children: [
                                _circleMoney(
                                    money:
                                        '${value.accountAmount != '' ? value.accountAmount : '0.00'}')
                              ],
                            )
                            // Text(
                            //   'R\$:${value.accountAmount != '' ? value.accountAmount : '0.00'}',
                            //   style: TextStyle(
                            //       color: Colors.white,
                            //       fontWeight: FontWeight.w600),
                            // ),
                            )
                      ],
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 20),
                    child: ProfileMenu(
                      menuList: _wallet,
                      menuTitle: 'My Wallet',
                      ontap: (e) {
                        String alias = e['alias'];

                        // if (alias == SkipAlias.DEPOSIT.alias) {
                        Navigator.pushNamed(context, alias);
                        // }
                        // if (alias == SkipAlias.FAIT.alias) {
                        //   Navigator.pushNamed(context, PageConst.FAIT_PAGE.code);
                        // }
                      },
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 20),
                    child: ProfileMenu(
                      menuList: _games,
                      menuTitle: 'My Games',
                      ontap: (e) {
                        Navigator.pushNamed(context, '${e['alias']}');
                        // Utils.showStatusDialog(context,text: '第一行内容\n第二行内容',showCloseBtn: true,success: true);
                      },
                    ),
                  )
                ],
              ),
            );
          },
        ));
  }

  _circleMoney({double? width, String? money}) {
    return Row(
      children: [
        Container(
          width: width,
          margin: EdgeInsets.only(left: 12),
          padding: EdgeInsets.only(top: 4, bottom: 4, left: 8, right: 8),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(20.0)),
              border: Border.all(color: Color(0xFF9C4EFF), width: 1)),
          child: Row(
            children: [
              Container(
                width: 24,
                height: 24,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: Color(0xFF9174FB),
                    borderRadius: BorderRadius.all(Radius.circular(12.0))),
                child: Text(
                  "R\$",
                  style: TextStyle(
                    fontSize: 10,
                    color: Colors.white,
                  ),
                ),
              ),
              Padding(
                padding: EdgeInsets.only(left: 5),
                child: Text(
                  money ?? '',
                  style: TextStyle(
                    fontSize: 10,
                    color: Colors.white,
                  ),
                ),
              )
            ],
          ),
        ),
        Padding(
          padding: EdgeInsets.only(left: 20),
          child: GestureDetector(
            onTap: (){
              Navigator.pushNamed(context, 'WithdrawnPage');
            },
            child: Image.asset(
            'images/wallet-app-bar.png',
            width: 24,
          ),
          ),
        )
      ],
    );
  }
}
